package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ForumPosts;
import com.ruoyi.system.service.IForumPostsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * forumController
 * 
 * @author zrj
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/system/forum")
public class ForumPostsController extends BaseController
{
    @Autowired
    private IForumPostsService forumPostsService;

    /**
     * 查询forum列表
     */
    @PreAuthorize("@ss.hasPermi('system:forum:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumPosts forumPosts)
    {
        startPage();
        List<ForumPosts> list = forumPostsService.selectForumPostsList(forumPosts);
        return getDataTable(list);
    }

    /**
     * 导出forum列表
     */
    @PreAuthorize("@ss.hasPermi('system:forum:export')")
    @Log(title = "forum", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumPosts forumPosts)
    {
        List<ForumPosts> list = forumPostsService.selectForumPostsList(forumPosts);
        ExcelUtil<ForumPosts> util = new ExcelUtil<ForumPosts>(ForumPosts.class);
        util.exportExcel(response, list, "forum数据");
    }

    /**
     * 获取forum详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:forum:query')")
    @GetMapping(value = "/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") Long postId)
    {
        return success(forumPostsService.selectForumPostsBypostId(postId));
    }

    /**
     * 新增forum
     */
    @PreAuthorize("@ss.hasPermi('system:forum:add')")
    @Log(title = "forum", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumPosts forumPosts)
    {
        return toAjax(forumPostsService.insertForumPosts(forumPosts));
    }

    /**
     * 修改forum
     */
    @PreAuthorize("@ss.hasPermi('system:forum:edit')")
    @Log(title = "forum", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumPosts forumPosts)
    {
        return toAjax(forumPostsService.updateForumPosts(forumPosts));
    }

    /**
     * 删除forum
     */
    @PreAuthorize("@ss.hasPermi('system:forum:remove')")
    @Log(title = "forum", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postIds}")
    public AjaxResult remove(@PathVariable Long[] postIds)
    {
        return toAjax(forumPostsService.deleteForumPostsBypostIds(postIds));
    }
}
